<#assign entityName="${nameInfo.entityName?uncap_first}">
<#assign serviceName="${nameInfo.serviceName?uncap_first}">
package ${nameInfo.actionPackage};

import java.util.List;
import org.apache.log4j.Logger;
import ${nameInfo.entityPackage}.${nameInfo.entityName};
import ${nameInfo.servicePackage}.${nameInfo.serviceName};
import com.opensymphony.xwork2.Action;

public class ${nameInfo.actionName}  {
	private static Logger logger = Logger.getLogger(${nameInfo.actionName}.class);
	private ${nameInfo.serviceName} ${serviceName};
	private ${nameInfo.entityName} ${entityName};
	private String actionMessage;

	public ${nameInfo.actionName}() {
	}
	
	public void set${nameInfo.serviceName}(${nameInfo.serviceName} ${serviceName}){
		this.${serviceName}=${serviceName};
	}
	
	public ${nameInfo.serviceName} get${nameInfo.serviceName}(){
		return ${serviceName};
	}
	
	public ${nameInfo.entityName} get${nameInfo.entityName}(){
		return ${entityName};
	}
	
	public void set${nameInfo.entityName}(${nameInfo.entityName} ${entityName}) {
		this.${entityName} = ${entityName};
	}
	
	public String getActionMessage() {
		return actionMessage;
	}

	public void setActionMessage(String actionMessage) {
		this.actionMessage = actionMessage;
	}
	    
	public String queryAll() throws Exception {
		List<${nameInfo.entityName}> list = ${serviceName}.queryAll${nameInfo.entityName}();
		logger.debug(list);
		JsonActionUtil util = JsonActionUtil.getSuccessJson("rows", list);
		util.write();
		return Action.NONE;
	}
	
	public String save() throws Exception {
		logger.debug(${entityName});
		JsonActionUtil util = new JsonActionUtil();
		try {
			${serviceName}.save${nameInfo.entityName}(${entityName});
			util.putData("message", "添加成功！");
			util.setSuccess(true);
		} catch (Exception e) {
			util.putData("message", "添加失败！");
			util.setSuccess(false);
			logger.fatal("程序发生错误", e);
		}
		util.write();
		return Action.NONE;
	}
	
	public String delete() throws Exception {
		logger.debug(${entityName});
		JsonActionUtil util = new JsonActionUtil();
		try {
			${entityName} = ${serviceName}.query${nameInfo.entityName}ByKey(${entityName});
			if (${entityName} != null) {
				${serviceName}.delete${nameInfo.entityName}(${entityName});
			}
			util.putData("message", "删除成功！");
			util.setSuccess(true);
		} catch (Exception e) {
			util.putData("message", "删除失败！");
			util.setSuccess(false);
			logger.fatal("程序发生错误", e);
		}
		util.write();
		return Action.NONE;
	}
	
	public String queryByKey() throws Exception {
		logger.debug(${entityName});
		${entityName} = ${serviceName}.query${nameInfo.entityName}ByKey(${entityName});
		logger.debug(${entityName});
		JsonActionUtil util = JsonActionUtil.getSuccessJson("data", ${entityName});
		util.write();
		return Action.NONE;
	}

	public String modify() throws Exception {
		logger.debug(${entityName});
		JsonActionUtil util = new JsonActionUtil();
		try {
			${serviceName}.update${nameInfo.entityName}(${entityName});
			util.putData("message", "修改成功！");
			util.setSuccess(true);
		} catch (Exception e) {
			util.putData("message", "修改失败！");
			util.setSuccess(false);
			logger.fatal("程序发生错误", e);
		}
		util.write();
		return Action.NONE;
	}
	
}
